package com.kefu.chat.vo;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.chat.model.ChatChannel;
import com.kefu.common.context.KefuContext;
import com.kefu.common.vo.AbstractSearchVo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.Objects;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "渠道配置")
public class ChatChannelSearchVo extends AbstractSearchVo {
    @ApiModelProperty(name = "channelType", value = "渠道类型：1桌面网站，2移动网站，3APP，4微信，5小程序，6企业微信")
    private Integer channelType;

    @ApiModelProperty(name = "channelName", value = "渠道名称")
    private String channelName;

    @ApiModelProperty(name = "createTimeStart", value = "创建开始时间")
    private Long createTimeStart;

    @ApiModelProperty(name = "createTimeEnd", value = "创建结束时间")
    private Long createTimeEnd;

    @ApiModelProperty(value = "状态：0禁用，1正常")
    private Integer channelStatus;

    @Override
    public LambdaQueryWrapper<ChatChannel> lambdaQuery() {
        LambdaQueryWrapper<ChatChannel> wrapper = Wrappers.lambdaQuery(ChatChannel.class);
        if (Objects.nonNull(channelType)) {
            wrapper.eq(ChatChannel::getChannelType, channelType);
        }
        if (StrUtil.isNotBlank(channelName)) {
            wrapper.like(ChatChannel::getChannelName, channelName);
        }
        if (Objects.nonNull(createTimeStart)) {
            wrapper.ge(ChatChannel::getCreateTime, createTimeStart);
        }
        if (Objects.nonNull(createTimeEnd)) {
            wrapper.le(ChatChannel::getCreateTime, createTimeEnd);
        }
        if (Objects.nonNull(channelStatus)) {
            wrapper.eq(ChatChannel::getChannelStatus, channelStatus);
        }
        wrapper.eq(ChatChannel::getTenantId, KefuContext.getTid());
        return wrapper;
    }
}